// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2005-4-29

#include "stdafx.h"
#include "guardcs.h"
#include "modcheck.h"
#include "proccheck.h"
#include "strcrypt.h"

namespace JoyGuard
{

//##ModelId=44C4B60E001F
GuardCS::GuardCS()
{
    m_waitEvent = NULL;
    m_modCheck  = NULL;
    m_procCheck = NULL;
}

//##ModelId=44C4B60E0020
GuardCS::~GuardCS()
{
}

#include "modcheckdata.h"
#include "proccheckdata.h"

//##ModelId=44C4B60E0022
bool GuardCS::Create(HANDLE hProcess, DWORD dwProcessId)
{
    m_waitEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);

    // module check.
    m_modCheck = new ModCheck();
    m_modCheck->m_process = hProcess;
    m_modCheck->m_processId = dwProcessId;
    m_modCheck->m_waitEvent = m_waitEvent;

    m_modCheck->LoadCheck(mod_check_bla3_hook_dll, sizeof(mod_check_bla3_hook_dll));
    m_modCheck->LoadCheck(mod_check_ogc10_1_ym0405_dll, sizeof(mod_check_ogc10_1_ym0405_dll));
    m_modCheck->LoadCheck(mod_check_dmi_vipice_dll, sizeof(mod_check_dmi_vipice_dll));
    m_modCheck->LoadCheck(mod_check_l0ry_dll, sizeof(mod_check_l0ry_dll));
    m_modCheck->LoadCheck(mod_check_mib_dll, sizeof(mod_check_mib_dll));
    m_modCheck->LoadCheck(mod_check_ltfx45_opengl32_dll, sizeof(mod_check_ltfx45_opengl32_dll));
	//added by deng 05-08-10
	m_modCheck->LoadCheck(mod_check_ym0405_dll, sizeof(mod_check_ym0405_dll));

    m_modCheck->Create();

    // process check.
    m_procCheck = new ProcCheck();
    m_procCheck->m_process = hProcess;
    m_procCheck->m_processId = dwProcessId;
    m_procCheck->m_waitEvent = m_waitEvent;

    m_procCheck->LoadCheck(proc_check_MosquitoCD_4_29_0_drw_exe, sizeof(proc_check_MosquitoCD_4_29_0_drw_exe));

    m_procCheck->Create();

    return true;
}

//##ModelId=44C4B60E0025
void GuardCS::Close()
{
    if(m_waitEvent != NULL)
    {
        ::SetEvent(m_waitEvent);
    }

    if(m_procCheck != NULL)
    {
        m_procCheck->Close();
        delete m_procCheck;
        m_procCheck = NULL;
    }
    if(m_modCheck != NULL)
    {
        m_modCheck->Close();
        delete m_modCheck;
        m_modCheck = NULL;
    }
    
    if(m_waitEvent != NULL)
    {
        ::CloseHandle(m_waitEvent);
        m_waitEvent = NULL;
    }
}

} // namespace JoyGuard
